<?php

namespace App\controllers;

use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use App\models\LoginForm;
use App\models\UserForm;

/**
 *
 */
class UserController extends \App\base\Controller
{
    private $token;
    private $msg;

    /**
    * Login interface
    */
    public function login(ServerRequestInterface $request,ResponseInterface $response)
    {
      $request_data = $request->getBody();
      $request_data = json_decode($request_data);
      $model = new LoginForm($request_data->username,$request_data->password,$this->ci);
      $model->login();
      $this->msg = $model->getMessage();
      return $response->withJson($this->msg['data'],$this->msg['code']);
    }

    /**
    * Init interface
    */
    public function init(ServerRequestInterface $request,ResponseInterface $response)
    {
      $this->token = $request->getQueryParams()['token'];
      $model = new UserForm($this->token,$this->ci);
      $model->init();
      $this->msg = $model->getMessage();
      return $response->withJson($this->msg['data'],$this->msg['code']);
    }
}
